/*
 * 所有路由入口
 */
import { RouteRecordRaw } from 'vue-router';
import { LAYOUT,ExceptionPage } from '/@/router/constant';
import { PageConstantEnum } from '/@/common/enums/sysEnum';
import { PageEnum } from '/@/common/enums/sysEnum';
import { t } from '/@/hooks/web/useI18n';

// 根页面
const rootRoute: RouteRecordRaw = {
  path: '/',
  name: 'Root',
  redirect: PageEnum.BASE_HOME,
  meta: {
    title: 'Root',
  },
};

// 登录页面
const loginRoute: RouteRecordRaw = {
  path: '/login',
  name: 'Login',
  component: () => import('/@/views/system/login/pc/login.vue'),
  meta: {
    title: t('routes.basic.login'),
  },
};

// 404页面
const page404: RouteRecordRaw = {
  path: '/:path(.*)*',
  name: 'PageNotFound',
  component: LAYOUT,
  meta: {
      title: '404',
      hideBreadcrumb: true,
      hideMenu: true,
  },
  children: [
      {
          path: '/:path(.*)*',
          name: 'PageNotFound404',
          component: ExceptionPage,
          meta: {
              title: '404',
              hideBreadcrumb: true,
              hideMenu: true,
          },
      },
  ],
};

const redirectRoute: RouteRecordRaw = {
  path: '/redirect',
  component: LAYOUT,
  name: PageConstantEnum.REDIRECT_ROUTE_NAME,
  meta: {
    title: PageConstantEnum.REDIRECT_NAME,
    hideBreadcrumb: true,
    hideMenu: true,
  },
  children: [
    {
      path: '/redirect/:path(.*)',
      name: PageConstantEnum.REDIRECT_NAME,
      component: () => import('/@/views/system/redirect.vue'),
      meta: {
        title: PageConstantEnum.REDIRECT_NAME,
        hideBreadcrumb: true,
      },
    },
  ],
};

// 静态路由
const modules = import.meta.glob('./modules/**/*.ts', { eager: true });
const routeModuleList: RouteRecordRaw[] = [];
Object.keys(modules).forEach((key) => {
  const mod = (modules as Recordable)[key].default || {};
  const modList = Array.isArray(mod) ? [...mod] : [mod];
  routeModuleList.push(...modList);
});

export const asyncRoutes = [page404, ...routeModuleList];

export const routerArray = [loginRoute,rootRoute,page404];
// export const routerArray = [loginRoute,page404];